package com.zzw.spring.quartz;

import org.quartz.*;
import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.calendar.AnnualCalendar;
import org.quartz.impl.triggers.SimpleTriggerImpl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class CalendarExample {

    public static void main(String[] args) {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        try {
            Scheduler scheduler = schedulerFactory.getScheduler();

            AnnualCalendar annualCalendar = new AnnualCalendar();
            Calendar calendar = new GregorianCalendar();
            calendar.add(Calendar.MONTH,5);
            calendar.add(Calendar.DATE,1);

            Calendar nationDay = new GregorianCalendar();
            nationDay.add(Calendar.MONTH,10);
            nationDay.add(Calendar.DATE,1);

            ArrayList<Calendar> calendars = new ArrayList<>();
            calendars.add(calendar);
            calendars.add(nationDay);

            annualCalendar.setDaysExcluded(calendars);

            scheduler.addCalendar("annualCalendar",annualCalendar,false,false);
            Date runDate = new Date();
            JobDetail job = new JobDetailImpl("job1","group1",SimpleJob.class);
            SimpleTriggerImpl trigger = new SimpleTriggerImpl("trigger1","group1",
                    runDate,
                    null,
                    SimpleTrigger.REPEAT_INDEFINITELY,
                    60L * 60L * 1000L);
            trigger.setCalendarName("annualCalendar");
            scheduler.scheduleJob(job,trigger);
            scheduler.start();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
